<?php 	include("head.php");
		include_once("paging_function.php");
?>
<script language="javascript">

function check()
{

	if(document.edit.name.value=='')
	
		{
			alert("Please Enter Name");
			document.edit.name.focus();
			return false;
		}
	if(document.edit.symbol.value=='')
	
		{
			alert("Please Enter Symbol");
			document.edit.symbol.focus();
			return false;
		}
	if(document.edit.type.value=='')
	
		{
			alert("Please Enter Type");
			document.edit.type.focus();
			return false;
		}
    if ( ( document.edit.status[0].checked == false )
   		 && ( document.edit.status[1].checked == false ) )
	
		{
			alert("Please Enter Status");
			return false;
		}

	return true;
}

</script>

<?php
/////////////////////////////////PAGING /////////////////
 	if(isset($_GET['page']) && $_GET['page']!='')
		{
		
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}
$limit=$adminpagelimit;
/////////////////////////////////////////////////////////////////	
?>
<?php
////////////////////////////////////////////    Block_---- DELETE  ///////////
if(isset($_POST['Submit']))
{
	$del=$_POST['del'];
	$no=count($del);
	if($no>0)
	{
		for($i=0;$i<$no;$i++)
		{
		mysql_query("DELETE FROM ".TOOLS."  WHERE toolsId= '".$del[$i]."' ");	   
		}
		echo '<script>window.location="tools.php?dlt=1"</script>';
	}
		$block=$_POST['count_UPDATE'];
	if($_POST['count_UPDATE']>0)
	{
		for($no_up=0; $no_up<$block;$no_up++)
		{
		if(isset($_POST['block'.$no_up]))
		{
		mysql_query("UPDATE ".TOOLS."  set status='N' WHERE toolsId='".$_POST['block'.$no_up]."'");
		}else{
		mysql_query("UPDATE ".TOOLS."  set status='Y' WHERE toolsId='".$_POST['block_hid'.$no_up]."'");
		}
		}
		echo '<script>window.location="tools.php?page='.$_GET['page'].'&loop='.$_GET['loop'].'&start='.$_GET['start'].'&blk=1"</script>';
	}
}

?>
<?php 
//////////////////////////////////////// insert edit query====================//////////
if(isset($_REQUEST['submit1']))
{
	if($_REQUEST['action']=='create')
	{
		$cont=addslashes($_REQUEST['content']);
		
		$insert_query=mysql_query("INSERT INTO `".TOOLS."` SET `title` ='".$_POST['name']."',`content` = '".$cont."',`linkpage` = '".$_POST['link']."',`status`='".$_POST['status']."'");
		echo '<script> window.location="tools.php?inst=1"</script>';
	}
	if($_REQUEST['action']=='edit')
	{
		$cont=addslashes($_REQUEST['content']);
		
		$UPDATE=mysql_query("UPDATE `".TOOLS."` SET `title` ='".$_POST['name']."',`content` = '".$cont."',`linkpage` = '".$_POST['link']."',`displayOrder`='".$_POST['display']."',`status`='".$_POST['status']."' WHERE `toolsId` ='".$_REQUEST['toolsId']."'") ;
		
		echo '<script> window.location="tools.php?updt=1"</script>';
	}
}
////////////////////////////////end////////////////////////////////////////////////////////
?>

<?php
	$search="SELECT * FROM ".TOOLS;

	$search=$search." limit $page,$limit";
	
	$searchquery=mysql_query($search) or die('error1'.mysql_error());
	
?>
<fieldset>
<legend class="LEGEND">TOOLS  MANAGEMENT</legend>
 <table width="100%" border="0" cellspacing="0" cellpadding="3">
 <tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr style="display:" id="editWin">

<td colspan='2' id="ShowMsg">
</td>
</tr>
<?php 
if((isset($_GET['blk']) && $_GET['blk']==1) || (isset($_GET['dlt']) && $_GET['dlt']==1) || (isset($_GET['inst']) && $_GET['inst']==1) || (isset($_GET['updt']) && $_GET['updt']==1) )
{
	?>
	<tr>
	
		<td colspan='2' style="color:#FF0000">
		<?php 
		if(isset($_GET['blk']) && $_GET['blk']==1)
		{
			echo $msg1="Value Blocked/Unblocked Successfully!!!";
		}
		if(isset($_GET['dlt']) && $_GET['dlt']==1)
		{
			echo $msg1="Value Deleted Successfully!!!";
		}
		if(isset($_GET['inst']) && $_GET['inst']==1)
		{
			echo $msg1="Value insert Successfully!!!";
		}
		if(isset($_GET['updt']) && $_GET['updt']==1)
		{
			echo $msg1="Value UPDATE Successfully!!!";
		}
		?></td>
	</tr>
	<?php
}
?>
</table>



  <table width="100%" border="0" cellspacing="0" cellpadding="3" class="tabbod">
  <?php
if(isset($_REQUEST['action']))
{
$editquery=mysql_query("SELECT * FROM ".TOOLS." WHERE toolsId='".$_REQUEST['toolsId']."'");

$fetch=mysql_fetch_array($editquery);
$value=ucfirst(stripslashes($fetch['content']));

?>
<tr><td colspan="5" id="edit_section" style="display:;">
<fieldset>
<legend class="LEGEND"> <?php echo ucfirst($_REQUEST['action']);?>Tools </legend>
<form name="edit" action="" method="POST" onSubmit="return check();" >
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
    <tr>
      <td width="17%" align="left" id="admin_text">Title</td>
      <td width="2%" align="left">::</td>
      <td width="81%" align="left"><input type="text" name="name" value="<?php echo $fetch['title'];?>" size="45"></td>
    </tr>
    <tr>
      <td width="17%" align="left" id="admin_text">Content</td>
      <td width="2%" align="left">::</td>
      <td width="81%" align="left"><?php 

	include_once ('../FCKeditor/fckeditor.php');	
	$oFCKeditor = new FCKeditor('content');	
	$oFCKeditor->BasePath = '../FCKeditor/';	
	$oFCKeditor->Value = $value;	
	$oFCKeditor->Width  = '90%';	
	$oFCKeditor->Height = '350';	
	$oFCKeditor->Create();

?></td>
    </tr>
  <tr>
      <td width="17%" align="left" id="admin_text">Link</td>
      <td width="2%" align="left">::</td>
      <td width="81%" align="left"><input type="text" name="link" value="<?php echo $fetch['linkpage'];?>" size="45"></td>
    </tr>
     <tr>
      <td width="17%" align="left" id="admin_text">Display Order</td>
      <td width="2%" align="left">::</td>
      <td width="81%" align="left"><input type="text" name="display" value="<?php echo $fetch['displayOrder'];?>" size="45"></td>
    </tr>
	<tr>
      <td width="27%" align="left" id="admin_text">Status</td>
      <td width="10%" align="left">::</td>
      <td width="63%" align="left">Active
		      <input type="radio" name="status" <?php if($fetch['status']=='Y'){?> checked="checked" <?php } ?> value="Y" >
		      &nbsp;&nbsp;Inactive
		      <input type="radio" name="status" <?php if($fetch['status']=='N'){?> checked="checked" <?php } ?> value="N" >        </td>
    </tr> 
    <tr>
      <td align="center">&nbsp;</td>
    <td align="center">&nbsp;</td>
    <td align="left"><input type="submit" name="submit1" value="<?php if($_REQUEST['action']=='create'){echo insert;}else echo UPDATE;?>" />
    	&nbsp;
    	<input type="button" value="Close" name="close_frm" id="close_frm" onClick="document.getElementById('edit_section').style.display = 'none';" /></td>
    </tr></table>
</form>
</fieldset>
  <?php } ?>
  </td></tr>
    <tr>
      <td height="40" colspan="2" align="left" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><strong>
        <!--Plan Management-->
       <a href="tools.php?action=create"> Create Tools </a></strong></font>       </td>
      <td colspan="3" align="right">&nbsp; </td>
    </tr>
    <?php

  if(mysql_num_rows($searchquery)>0)
  {

  ?><form name="form_admin_management" action="" method="post">
    <tr bgcolor="#6F8DBC">
      <td width="4%" height="28" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
	  <td align="left" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Title</strong></td>
	  <!--      <td width="13%" align="center" style="color:#ffffff;font-size:12px;"><strong>Edit</strong></td>-->
      <td width="8%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Edit</strong></td>
      <td width="7%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Block</strong></td>
      <td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
    </tr>
    <?php 
  $count=0;
  $sno=1;
  $loop=0;
  while($searcharray=mysql_fetch_array($searchquery))
  {
  $loop++;
		if($loop == 1)
		 $bgcolor = "#F0F0FF";
		else 
		$bgcolor = "#CCCCFF";
?>
    <tr bgcolor="<?php echo $bgcolor; ?>">
      <td height="32" style="color:#000000;font-size:12px;"><strong><?php echo $sno+$_GET['page'];//echo $searcharray['usercode']; ?></strong></td>
      <td align="left" valign="middle" style="color:#000000;font-size:12px;"><?php echo ($searcharray['title']); ?></td>
      <td align="center" valign="middle"><a href="tools.php?action=edit&toolsId=<?php echo $searcharray['toolsId'];?>" ><img src="images/edit_icon.gif" border="0"/></a></td>
      <td align="center" valign="middle"><input type="checkbox" name="block<?php echo $count; ?>" value="<?php echo $searcharray['toolsId']; ?>" <?php if($searcharray['status']=='N') echo "checked";?>>
        <input type="hidden" name="block_hid<?php echo $count; ?>" value="<?php echo $searcharray['toolsId'];?>"></td>
      <td align="center"><input type="checkbox" name="del[]" value="<?php echo $searcharray['toolsId'];?>"></td>
    </tr>
    <?php 
  $count++;
  $sno++;
 		 if($loop == 2)
			{
			$loop = 0;
			}	
		 }
		   ?>
    <tr>
      <td colspan="2">&nbsp;</td>
      <td colspan="5" align="right"><input type="hidden" name="count_UPDATE" value="<?php echo $count; ?>">
          <input type="submit" name="Submit" value="Update"></td>
    </tr>
    <tr>
      <td colspan="7" align="center" style="color:#FF0000"><?php echo paging($search,$page,$limit,'',$param);?></td>
    </tr>
    <?php

}

else

{

?>
<tr bgcolor="#6F8DBC">
      <td width="4%" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
	  <td align="left" style="color:#ffffff;font-size:12px;"><strong>Title</strong></td>
	  <td width="8%" align="center" style="color:#ffffff;font-size:12px;"><strong>Edit</strong></td>
      <td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Block</strong></td>
      <td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
    </tr>
    <tr>
      <td colspan="8" align="left">&nbsp;&nbsp;&nbsp;<strong><font color="#FF0000" class="DISPLAYMESSAGES">No Result Found!</font></strong></td>
    </tr>
    <?php

  }

  ?></form>
  </table>
  </td></tr></table>
</fieldset>
<?php 

include("foot.php");?>